package com.example.steveaoblogdemo.controller;

import com.example.steveaoblogdemo.service.impl.CategoryServiceImpl;
import com.example.steveaoblogdemo.utils.Result;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
public class CategoryController {
    @Resource
    CategoryServiceImpl categoryService;

    @GetMapping("/category/queryCategory")
    public Result<?> queryCategory(){
        return categoryService.queryCategory();
    }

    @PostMapping("/category/addCategory")
    public int addCategory(@RequestParam(required = false)Integer id,@RequestParam(defaultValue = "")String cName){
        return categoryService.addCategory(id,cName);
    }

    @GetMapping("/category/query")
    public Result<?> query(@RequestParam(defaultValue = "1")Integer pageNum,@RequestParam(defaultValue = "10")Integer pageSize,@RequestParam(defaultValue = "")String search){
        return categoryService.query(pageNum,pageSize,search);
    }

    @GetMapping("/category/queryCategoryById")
    public Result<?> queryById(@RequestParam(required = false)Integer id){
        return categoryService.queryById(id);
    }

    @PutMapping("/category/updateCategory")
    public int update(@RequestParam(defaultValue = "")String cName,@RequestParam(required = false)Integer id){
        return categoryService.updateCategory(cName,id);
    }

    @PutMapping("/category/deleteById")
    public Result<?> delete(@RequestParam(required = false) Integer id){
        return categoryService.deleteCategory(id);
    }

    @GetMapping("/category/queryByCategory")
    public Result<?> queryByTag(@RequestParam(required = false)Integer id){
        return categoryService.queryByCategory(id);
    }
}
